/**
 * 百度地图 - 浏览器定位
 * 注意，此处并不是精确定位，PC端定位模糊，移动端更加精确
 * @type {HTMLElement}
 */
/*
var address = document.getElementById('address');
var point_this = document.getElementById('point_this');
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);   //初始化地址 北京
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
    // console.log(r.point.lng+' = '+r.point.lat);
    if(this.getStatus() == BMAP_STATUS_SUCCESS){
        var mk = new BMap.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);
        // 创建地理编码实例
        var myGeo = new BMap.Geocoder();
        // 根据坐标得到地址描述
        myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result){
            if (result){
                address.attributes[2].value = result.address;   //具体到街道
                point_this.attributes[2].value = r.point.lng + ',' + r.point.lat; //具体到经纬度
            }else {
                address.attributes[2].value = "ERROR";   //具体到街道
                point_this.attributes[2].value = "ERROR"; //具体到经纬度
            }
        });
    }
    else {
        alert('请开启定位权限，错误提示 '+this.getStatus());
        setTimeout(window.location.href='error',1000);
    }
});
console.log('this');
*/
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
// var address = document.getElementById('address');
var point_this = document.getElementById('point_this');

var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
    if(this.getStatus() == BMAP_STATUS_SUCCESS){
        var mk = new BMap.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);
        point_this.attributes[2].value = r.point.lng + ',' + r.point.lat; //具体到经纬度
        // alert('您的位置：'+r.point.lng+','+r.point.lat);
    }
    else {
        alert('请开启定位权限，错误提示 '+this.getStatus());
        setTimeout(window.location.href='error',1000);
    }
},{enableHighAccuracy: true})